package com.taikang.hmp.frame.user.action.view;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.taikang.hmp.frame.common.TKException;
import com.taikang.hmp.frame.common.datastructre.Dto;
import com.taikang.hmp.frame.common.datastructre.support.BaseDto;
import com.taikang.hmp.frame.common.datastructre.support.ResponseDto;
import com.taikang.hmp.frame.common.web.action.BaseAction;
import com.taikang.hmp.frame.user.service.IUserManagementService;

/** 
 * 用户管理
 * author:qrp
 * time:2015年11月10日 下午1:51:09
 */
public class UserManagementAction extends BaseAction{
	private static final long serialVersionUID = 1L;
	private static Logger logger = LoggerFactory.getLogger(UserManagementAction.class);
	
	private IUserManagementService userManagementService;


	public IUserManagementService getUserManagementService() {
		return userManagementService;
	}

	public void setUserManagementService(
			IUserManagementService userManagementService) {
		this.userManagementService = userManagementService;
	}


	public String executeAction(){
		if("getAllUser".equals(requestDto.getMethod())){
			logger.info("--【获取所有用户】 method:getAllUser -- ");
			return getAllUser();
		}else if("saveUser".equals(requestDto.getMethod())){
			logger.info("--【获取所有用户】 method:getAllUser -- ");
			return saveUser();
		}else{
			throw new TKException("no support method:"+requestDto.getMethod());
		}
	}
	
	
	/**
	 * 取得所有用户列表
	 * @return
	 */
	public String getAllUser(){
		ResponseDto responseDto = new ResponseDto();
		
		List<Dto> resultList = userManagementService.getAllUser();
		
		Dto resultDto = new BaseDto();
		resultDto.put("resultlist", resultList);
		responseDto.pushResultDto(resultDto);
		super.setDataMap(responseDto);
		
		return SUCCESS;
	}
	/**
	 * 保存用户信息
	 * @return
	 */
	public String saveUser(){
		ResponseDto responseDto = new ResponseDto();
		
		//获取参数
		Dto paramDto = requestDto.getRequestlist().get(0);
		paramDto = super.appendRequestBase(paramDto, requestDto);
		
		boolean resultInfo= userManagementService.saveUser(paramDto);
		
		if(resultInfo){
			logger.info("............信息保存成功..............");
		}else{
			logger.info("............信息保存失败..............");
		}
		
		Dto resultDto = new BaseDto();
		responseDto.pushResultDto(resultDto);
		super.setDataMap(responseDto);
		
		return SUCCESS;
	}
	/**
	 * 删除用户信息
	 * @return
	 */
	public String delUser(){
		ResponseDto responseDto = new ResponseDto();
		
		//获取参数
		Dto paramDto = requestDto.getRequestlist().get(0);
		paramDto = super.appendRequestBase(paramDto, requestDto);
		
		boolean resultInfo= userManagementService.saveUser(paramDto);
		
		if(resultInfo){
			logger.info("............信息保存成功..............");
		}else{
			logger.info("............信息保存失败..............");
		}
		
		Dto resultDto = new BaseDto();
		responseDto.pushResultDto(resultDto);
		super.setDataMap(responseDto);
		
		return SUCCESS;
	}

}
